//
//  MJModifyNicknameController.m
//  MJ
//
//  Created by qiaoBu on 2017/12/8.
//  Copyright © 2017年 lina. All rights reserved.
//

#import "MJModifyNicknameController.h"
#import "MJModifyNicknameView.h"
#import "MJMyInfoViewModel.h"
#import "MJLoginViewController.h"

@interface MJModifyNicknameController ()

@property (nonatomic, strong) MJModifyNicknameView *modifyView;

@end

@implementation MJModifyNicknameController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
     self.navgationBar.titleLabel.text = @"昵称";
     self.view.backgroundColor = RGBColor(242,242,242);
    
    [self commonInitView];
}
- (void)commonInitView{
    
   _modifyView = [[MJModifyNicknameView alloc] initWithFrame:CGRectMake(0, self.navgationBar.height+15, kScreenWidth, kScreenHeight-64-15)];
    [self.view addSubview:_modifyView];
    
    @weakify(self)
    [_modifyView setModifyBlcok:^(NSString *nickName) {
        
        @strongify(self)
        [self requestUploadNickname:nickName];
        
    }];
    
}
- (void)requestUploadNickname:(NSString *)name{
    
    if ((name.length == 0)||([name isEqualToString:@"null"])) {
        
        [TJMBProgressView showTingJianText:@"昵称不能为空"];
        
    }else{
        
        [[NSUserDefaults standardUserDefaults] setObject:name forKey:MJ_Name];
        [self.navigationController popViewControllerAnimated:YES];
    }
    
    
//    NSMutableDictionary *nameDict = [NSMutableDictionary dictionary];
//    [nameDict setObject:[NSString stringWithFormat:@"%@",name] forKey:@"alias"];
//    [MJMyInfoViewModel requestChangeInfoWithDictionary:nameDict Success:^(NSString *stateCode, NSString *messageState) {
//
//        if ([stateCode isEqualToString:@"001"])
//        {
//            [self.navigationController popViewControllerAnimated:YES];
//        }
//        else if ([stateCode isEqualToString:@"203"])
//        {
//            MJLoginViewController *loginController = [[MJLoginViewController alloc] init];
//            [self.navigationController pushViewController:loginController animated:YES];
//        }
//        else
//        {
//            [TJMBProgressView showTingJianText:messageState];
//        }
//    } failure:^(NSError *error) {
//
//        [TJMBProgressView showTingJianText:networkError];
//    } netWorkState:^(BOOL netWorkState) {
//
//    }];
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    [self.view endEditing:YES];
    [self.modifyView.nameField resignFirstResponder];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
